package ru.btabank.dom.xpath.expression;

import org.w3c.dom.Node;

import ru.btabank.dom.util.DOMUtil;

public class RootStep extends Step {

    public RootStep() {
    }

    public NodeSet select(NodeSet source) {
        NodeSet target;
        Node sourceNode, documentNode;

        target = new NodeSet();
        for (int sourceIndex = 0; sourceIndex < source.getLength(); sourceIndex++) {
            sourceNode = source.item(sourceIndex);
            documentNode = DOMUtil.getOwnerDocument(sourceNode);
            if (documentNode != null)
                target.add(documentNode);
        }
        return target;
    }

    public NodeSet build(NodeSet source) {
        return this.select(source);
    }

    public String toString() {
        return "/";
    }
}
